﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace SerialisationProject
{
    public class FileHelper
    {
        /// <summary>
        /// Writes contents to the current filePath - not used atm
        /// More Details: http://msdn.microsoft.com/en-us/library/6ka1wd3w.aspx
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="content"></param>
        /// <returns></returns>
        //public static bool Write(string filePath, string content)
        //{
        //    bool result = false;
        //    using (StreamWriter sw = new StreamWriter(filePath))
        //    {
        //        sw.Write(content);
        //    }
        //    result = true;
        //    return result;
        //}

        /// <summary>
        /// Reads from the current filePath
        /// More Details: http://msdn.microsoft.com/en-us/library/db5x7c0d.aspx
        /// </summary>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public static string Read(string filePath)
        {
            string results = string.Empty;
            try
            {
                // Create an instance of StreamReader to read from a file.
                // The using statement also closes the StreamReader.
                using (StreamReader sr = new StreamReader(filePath))
                {
                    String line;
                    // Read and display lines from the file until the end of 
                    // the file is reached.
                    while ((line = sr.ReadLine()) != null)
                    {
                        results = results + line;
                    }
                }
            }
            catch (Exception e)
            {
                //// Let the user know what went wrong.
                //Console.WriteLine("The file could not be read:");
                //Console.WriteLine(e.Message);
            }
            return results;
        }
    }
}
